package financial.sharing.center.contract.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.contract.model.entity.ContractClause;
import financial.sharing.center.contract.service.ContractClauseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ContractClause
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/4/11
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/contract/contract/clause/")
public class ContractClauseController {

    @Autowired
    private ContractClauseService contractClauseServiceImpl;

    @PostMapping(value = "get/all/contract/clause")
    public R getAllContractClause(Integer contractId,
                                  Integer contractDetailId,
                                  Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<ContractClause> result = this.contractClauseServiceImpl.getAllContractClause(contractId,contractDetailId);
        return R.ok(result);
    }

    @PostMapping(value = "compile/one/contract/clause")
    public R compileOneContractClause(@RequestBody ContractClause contractClause){
        Integer result = this.contractClauseServiceImpl.compileOneContractClause(contractClause);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "create/one/contract/clause")
    public R createOneContractClause(@RequestBody ContractClause contractClause){
        Integer result = this.contractClauseServiceImpl.createOneContractClause(contractClause);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/contract/clause")
    public R deleteOneContractClause(Integer id){
        Integer result = this.contractClauseServiceImpl.deleteOneContractClause(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

}
